<?php

class DBMInFilterTranslator implements DBMTranslator {
	private static $translationDictionary = array(
		DBManager::TYPE_MSSQL => "%s IN %s",  
		DBManager::TYPE_MYSQL => "%s IN %s",
		DBManager::TYPE_POSTGRESQL => "%s IN %s"
	);
	
	public static function translateToMySQL($filter, $command = null) {
		// get the dictionary
		$dictionary = self::$translationDictionary;
		
		// format the property
		$property = $filter->getProperty();
		
		// format the possible values
		if(is_array($filter->getPossibleValues())){
			$possibleValues = DBMGeneralTranslator::translateToMySQL($filter->getPossibleValues(), $command);	
		} else {
			$possibleValues = "( " . DBMGeneralTranslator::translateToMySQL($filter->getPossibleValues(), $command) . " )";
		}
		
		// format and return
		return sprintf($dictionary[DBManager::TYPE_MSSQL], $property, $possibleValues);
	}
	
	public static function translateToPostgreSQL($filter, $command = null) {
		// get the dictionary
		$dictionary = self::$translationDictionary;
		
		// format the property
		$property = $filter->getProperty();
		
		// format the possible values
		if(is_array($filter->getPossibleValues())){
			$possibleValues = DBMGeneralTranslator::translateToPostgreSQL($filter->getPossibleValues());	
		} else {
			$possibleValues = "( " . DBMGeneralTranslator::translateToPostgreSQL($filter->getPossibleValues()) . " )";
		}
		
		// format and return
		return sprintf($dictionary[DBManager::TYPE_MSSQL], $property, $possibleValues);
	}
	
	public static function translateToSQLServer($filter, $command = null) {
		// get the dictionary
		$dictionary = self::$translationDictionary;
		
		// format the property
		$property = $filter->getProperty();
		
		// format the possible values
		if(is_array($filter->getPossibleValues())){
			$possibleValues = DBMGeneralTranslator::translateToSQLServer($filter->getPossibleValues(), $command);	
		} else {
			$possibleValues = "( " . DBMGeneralTranslator::translateToSQLServer($filter->getPossibleValues(), $command) . " )";
		}
		
		// format and return
		return sprintf($dictionary[DBManager::TYPE_MSSQL], $property, $possibleValues);
	}
}

?>
